package com.xsomnus.java_basic.retry;

import com.github.rholder.retry.Retryer;
import com.github.rholder.retry.RetryerBuilder;
import com.github.rholder.retry.StopStrategies;
import com.github.rholder.retry.WaitStrategies;

import java.util.concurrent.TimeUnit;

/**
 * @author @xsomnus666_xiawenye★
 * @since 2019-08-12 23:00
 * 只有经历过地狱般的磨砺，才能练就创造天堂的力量； 只有流过血的手指，才能弹出世间的绝响
 */
public class GuavaRetryTest {



    public static void main(String[] args) {

        HelloService helloService = new HelloService();

        Retryer<String> retryer = RetryerBuilder.<String>newBuilder()
                .retryIfExceptionOfType(HelloRetryException.class)
                .retryIfResult(String::isEmpty)
                .withWaitStrategy(WaitStrategies.fixedWait(3, TimeUnit.SECONDS))
                .withStopStrategy(StopStrategies.stopAfterAttempt(4))
                .build();

        try {
            String call = retryer.call(helloService::hello);
            System.out.println(call);
        } catch (Exception e){
            e.printStackTrace();
        }

    }

}
